import Cookies from 'js-cookie'

export function setToken (token) {
    const isBrowser = !!JSON.parse(process.env.VUE_APP_IS_BROWSER)
    if (isBrowser) {
        Cookies.set('token', token)
    } else {
        window.localStorage.setItem('token', token)
    }
}
export function getToken () {
    const isBrowser = !!JSON.parse(process.env.VUE_APP_IS_BROWSER)
    if (isBrowser) {
        return Cookies.get('token')
    } else {
        return window.localStorage.getItem('token')
    }
}
export function removeToken () {
    const isBrowser = !!JSON.parse(process.env.VUE_APP_IS_BROWSER)
    if (isBrowser) {
        Cookies.remove('token')
    } else {
        window.localStorage.removeItem('token')
    }
}

// 获取本地储存的 语言
export function getLang () {
    return window.localStorage.getItem('lang') || 'zh'
}

export function setLang (value) {
    return window.localStorage.setItem('lang', value)
}

export function getItem (key) {
    return window.localStorage.getItem(key)
}
export function setItem (key, value) {
    return window.localStorage.setItem(key, value)
}
